package com.ikangtai.shecare.common.baseView.pickerDialog;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

import com.ikangtai.shecare.R;
import com.ikangtai.shecare.common.Constant;

public class MyInfoPickerDialog extends AlertDialog implements
        DialogInterface.OnClickListener {

    private MyInfoPicker mBrandPicker;
    private int brand = 0;
    private OnBrandSetListener mOnBrandSetListener;
    private String dialogName;

    public MyInfoPickerDialog(Context context, String dialogName) {
        super(context);
        mBrandPicker = new MyInfoPicker(context, dialogName);
        this.dialogName = dialogName;
        if (dialogName.equals(Constant.MENSES_LENGTH)) {
            brand = 5;
        } else if (dialogName.equals(Constant.PERIOD_LENGTH)) brand = 28;
        setView(mBrandPicker);
        /*
         *实现接口，实现里面的方法
         */
        mBrandPicker
                .setOnBrandChangedListener(new MyInfoPicker.OnBrandChangedListener() {
                    @Override
                    public void onTemperatureChanged(MyInfoPicker view, int minute) {
                        brand = minute;
                    }
                });

        setButton(context.getString(R.string.setting), this);
        setButton2(context.getString(R.string.cancel), (OnClickListener) null);
        setTitle(dialogName);
    }

    /*
     *接口回調
     *控件 秒数
     */
    public interface OnBrandSetListener {
        void OnBrandSet(AlertDialog dialog, String brand);
    }

    /*
     * 对外公开方法让Activity实现
     */
    public void setOnBrandSetListener(OnBrandSetListener callBack) {
        mOnBrandSetListener = callBack;
    }

    public void onClick(DialogInterface arg0, int arg1) {
        if (mOnBrandSetListener != null) {
            if (dialogName.equals(Constant.MENSES_LENGTH) || dialogName.equals(Constant.PERIOD_LENGTH))
                mOnBrandSetListener.OnBrandSet(this, String.valueOf(brand));
            else if (dialogName.equals(Constant.MENSES_REGULAR)) {
                mOnBrandSetListener.OnBrandSet(this, MyInfoPicker.regular[brand]);
            }
        }
    }
}
